<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('')"/>
    <th:block th:include="include :: select2-css"/>
    <style>
        .popover-show {
            cursor: pointer;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-plan-add">
        <input id="childProjectId" name="childProjectId" th:value="*{childProjectId}" hidden="true">
        <input id="childId" name="childId" th:value="*{childId}" hidden="true">
        <input id="age" name="age" th:value="*{age}" hidden="true">
        <input id="linkNo" name="linkNo" th:value="*{linkNo}" hidden="true">


        <div class="form-group">
            <label class="col-sm-2 control-label is-required">项目：</label>
            <div class="col-sm-4">
                <select id="linkProject" name="linkProject" class="form-control">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var projectData = {

        "age4": [
            {
                "projectCode": "S0506",
                "projectName": "原地剪刀跳",
                "childList": []
            },
            {
                "projectCode": "S0504",
                "projectName": "放学跳",
                "childList": []
            },
            {
                "projectCode": "S0912",
                "projectName": "上下台阶",
                "childList": []
            },
            {
                "projectCode": "S0516",
                "projectName": "兔子跳",
                "childList": []
            },
            {
                "projectCode": "S0502",
                "projectName": "小马跳",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "双脚跳",
                "childList": [
                    {
                        "projectCode": "S050702",
                        "projectName": "纵向"
                    },
                    {
                        "projectCode": "S050704",
                        "projectName": "横向"
                    },
                    {
                        "projectCode": "S050703",
                        "projectName": "旋转"
                    }
                ]
            },
            {
                "projectCode": "S1009",
                "projectName": "跑步游戏",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "加速跑",
                "childList": [
                    {
                        "projectCode": "S100201",
                        "projectName": "追物跑"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "夹沙包",
                "childList": [
                    {
                        "projectCode": "S100801",
                        "projectName": "夹沙包走"
                    },
                    {
                        "projectCode": "S100802",
                        "projectName": "夹沙包跑"
                    }
                ]
            },
            {
                "projectCode": "S0910",
                "projectName": "抱球走路",
                "childList": []
            },
            {
                "projectCode": "S0901",
                "projectName": "螃蟹走",
                "childList": []
            },
            {
                "projectCode": "S0703",
                "projectName": "飞碟抛球",
                "childList": []
            },
            {
                "projectCode": "S1302",
                "projectName": "绕桩推球",
                "childList": []
            },
            {
                "projectCode": "S1303",
                "projectName": "举圈钻圈",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "滚球游戏",
                "childList": [
                    {
                        "projectCode": "S080901",
                        "projectName": "双手推球竞速"
                    },
                    {
                        "projectCode": "S080902",
                        "projectName": "灵敏圈滚球"
                    },
                    {
                        "projectCode": "S080903",
                        "projectName": "外力推球"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "倒爬游戏",
                "childList": [
                    {
                        "projectCode": "S041001",
                        "projectName": "倒爬2米"
                    },
                    {
                        "projectCode": "S041002",
                        "projectName": "阻力倒爬"
                    }
                ]
            },
            {
                "projectCode": "S0403",
                "projectName": "猫爬",
                "childList": []
            },
        ],
        "age5": [
            {
                "projectCode": "",
                "projectName": "俯卧撑",
                "childList": [
                    {
                        "projectCode": "S1204",
                        "projectName": "扶墙俯卧撑"
                    }
                ]
            },
            {
                "projectCode": "S1208",
                "projectName": "趴地游泳",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "双脚跳",
                "childList": [
                    {
                        "projectCode": "S050702",
                        "projectName": "纵向"
                    },
                    {
                        "projectCode": "S050704",
                        "projectName": "横向"
                    },
                    {
                        "projectCode": "S050703",
                        "projectName": "旋转"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "剪刀跳",
                "childList": [
                    {
                        "projectCode": "S050301",
                        "projectName": "直线（跳绳）"
                    },
                    {
                        "projectCode": "S050302",
                        "projectName": "绳梯"
                    },
                    {
                        "projectCode": "S050303",
                        "projectName": "踏板"
                    },
                    {
                        "projectCode": "S050304",
                        "projectName": "泡沫半轴"
                    },
                    {
                        "projectCode": "S050305",
                        "projectName": "其他"
                    }
                ]
            },
            {
                "projectCode": "S0502",
                "projectName": "小马跳",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "蹦床",
                "childList": [
                    {
                        "projectCode": "S051201",
                        "projectName": "基本动作"
                    },
                    {
                        "projectCode": "S051202",
                        "projectName": "节奏训练"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "匍匐爬",
                "childList": [
                    {
                        "projectCode": "S040201",
                        "projectName": "基本动作"
                    },
                    {
                        "projectCode": "S040202",
                        "projectName": "钻爬"
                    },
                    {
                        "projectCode": "S040203",
                        "projectName": "障碍组合"
                    }
                ]
            },
            {
                "projectCode": "S0405",
                "projectName": "蜘蛛爬",
                "childList": []
            },
            {
                "projectCode": "S0403",
                "projectName": "猫爬",
                "childList": []
            },
            {
                "projectCode": "",
                "projectName": "障碍走（跑）",
                "childList": [
                    {
                        "projectCode": "S050301",
                        "projectName": "栏架等跨越（高）"
                    },
                    {
                        "projectCode": "S050302",
                        "projectName": "灵敏圈等跨越（远）"
                    },
                    {
                        "projectCode": "S050303",
                        "projectName": "跳箱等翻越"
                    },
                    {
                        "projectCode": "S050304",
                        "projectName": "锥桶等变向"
                    }
                ]
            },



        ],
        "age6": [
            {
                "projectCode": "",
                "projectName": "肩上推举",
                "childList": [
                    {
                        "projectCode": "S110201",
                        "projectName": "学肩上推举"
                    },
                    {
                        "projectCode": "S110202",
                        "projectName": "基本动作"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "俯卧撑",
                "childList": [
                    {
                        "projectCode": "S110401",
                        "projectName": "扶墙俯卧撑"
                    },
                    {
                        "projectCode": "S110402",
                        "projectName": "跪姿俯卧撑"
                    }
                ]
            },
            {
                "projectCode": "S1107",
                "projectName": "仰卧起坐",
                "childList": []
            },
            {
                "projectCode": "S0506",
                "projectName": "原地剪刀跳",
                "childList": []
            }


        ],
        "age7": [
            {
                "projectCode": "",
                "projectName": "肩上推举",
                "childList": [
                    {
                        "projectCode": "S110201",
                        "projectName": "学肩上推举"
                    },
                    {
                        "projectCode": "S110202",
                        "projectName": "基本动作"
                    }
                ]
            },
            {
                "projectCode": "",
                "projectName": "俯卧撑",
                "childList": [
                    {
                        "projectCode": "S110401",
                        "projectName": "扶墙俯卧撑"
                    },
                    {
                        "projectCode": "S110402",
                        "projectName": "跪姿俯卧撑"
                    }
                ]
            },
            {
                "projectCode": "S1107",
                "projectName": "仰卧起坐",
                "childList": []
            },
            {
                "projectCode": "S0506",
                "projectName": "原地剪刀跳",
                "childList": []
            }

        ]
    };


</script>
<script th:inline="javascript">
    // 权限

    // 字典

    var prefix = ctx + "business/prepareClass";
    var i = 0;
    $(function () {
        //加载本节课学员
         loadLinkProject();
    });

    function loadLinkProject() {
        $("#linkProject").empty();
        var age = $("#age").val();
        var projectList = [];
        if (age == 4) {
            projectList = projectData.age4;
        }
        if (age == 5) {
            projectList = projectData.age5;
        }
        if (age == 6) {
            projectList = projectData.age6;
        }
        if (age == 7) {
            projectList = projectData.age7;
        }
        var html = "";
        html += "<option value=\"\" >请选择</option>";
        var projectCodes=[];
        for (var i in projectList) {
            var json = projectList[i];
            if (json.childList.length > 0) {
                for (var j in json.childList) {
                    projectCodes.push(json.childList[j].projectCode);
                }
            } else {
                projectCodes.push(json.projectCode);
            }
        }
        for (var i in projectList) {
            var json = projectList[i];
            if (json.childList.length > 0) {
                html += '<optgroup label="--' + json.projectName + '--">';
                for (var j in json.childList) {
                    html += "<option value=\"" + json.childList[j].projectCode + "\" >" + json.childList[j].projectName + "</option>";
                }
                html += '</optgroup>';
            } else {
                html += "<option value=\"" + json.projectCode + "\" >" + json.projectName + "</option>";
            }
        }
        $("#linkProject").append(html);

    }

    // 项目选择改变
    function linkProjectChange() {
        var newProject = $("#linkProject").val();
        var childId = $("#childId").val();
        var link23=['S0201','S1208'];
        var link8=['S1717'];
        var html="";
        $("#linkNo").empty();
        html+="<option value=\"\">请选择</option>";
        if(link23.indexOf(newProject)>-1){
            html+="<option value=\"2\">引入2</option>";
            html+="<option value=\"3\">引入3</option>";
        }else if(link8.indexOf(newProject)>-1){
            html+="<option value=\"8\">游戏</option>";
        }else {
            html+="<option value=\"4\">项目1</option>";
            html+="<option value=\"5\">项目2</option>";
            html+="<option value=\"6\">项目3</option>";
            html+="<option value=\"7\">项目4</option>";
        }
        $("#linkNo").append(html);



    };

    function linkNoChange() {
        var childId = $("#childId").val();
        var linkNo = $("#linkNo").val();
        //获取需要替换环节原本项目
        var oldProject="";
        $.ajax({
            url: ctx+"business/courseChildProject/getProject?childCourseId=" + $("#childCourseId").val()+"&childId="+ childId,
            type: "get",
            async:false,
            success: function (result) {
                reqData=result.data;
                switch (linkNo) {
                    case "2":oldProject =result.data.initTwo;break;
                    case "3":oldProject =result.data.initThree;break;
                    case "4":oldProject =result.data.initFour;break;
                    case "5":oldProject =result.data.initFive;break;
                    case "6":oldProject =result.data.initSix;break;
                    case "7":oldProject =result.data.initSeven;break;
                    case "8":oldProject =result.data.initEight;break;
                }
            }
        });
        //获取项目已被替换次数
        $.ajax({
            url: ctx+"business/childProjectConfig/getProjectReplaceTimes?childId=" + childId+"&projectCode="+ oldProject,
            type: "get",
            async:false,
            success: function (result) {
                if(result.data !=undefined){
                    $.modal.msg("【"+result.data.projectName+"】已被替换"+(result.data.replaceTimes==null?0:result.data.replaceTimes)+"次");
                }
            }
        })
        // 当被替换的项目为【大滑板】时需选用两个替换项目
        if(oldProject.indexOf("S0301")>-1){
             $("#linkProject5").css("display","block");
            loadLinkProject1();
        }else {
            $("#linkProject5").css("display","none");
        }

    }

    function submitHandler() {
        var projectCode = $("#linkProject").val();
        var childId = $("#childId").val();
        var linkNo = $("#linkNo").val();
        var childProjectId = $("#childProjectId").val();
        var reqData={
            "id":childProjectId,
            "linkNo":linkNo,
            "projectCode":projectCode,
            "childId":childId
        };
        $.modal.confirm('替换后  不可恢复为原项目  ，请确认是否替换。',function () {
            $.ajax({
                url: prefix + "/replaceDifficulty",
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: JSON.stringify(reqData),
                success: function (result) {
                    $.operate.successCallback(result);
                    $.table.refresh();
                }
            })

        });

    }

</script>
</body>

</html>